<template>
	<view>
		<view class="homeBoxChaoren" v-if="newZuJianList.length != 0"
			:style="{ paddingTop: uniPlatform == 'app' ? stateLanHei + 'px' : 0 }">
			<!--  #ifdef  H5 || APP-PLUS -->
			<!-- <view :style="{ backgroundColor: '#bd9262', width:'100%',height: topHeight + 'px'}">
			</view> -->
			<!--  #endif -->
			<view class="bjBoxCCrr" style="display: flex; flex-direction: column" v-for="(item, index) in newZuJianList"
				:key="index">
				<view v-if="item.code == '0017'">
					<shareFriCCrr :shareObj="item.info"></shareFriCCrr>
				</view>
				<view v-if="item.code == '0012'">
					<searchBoxCCrr :searchBgcolor="searchBgcolor" :searchDataObj="item"></searchBoxCCrr>
				</view>
				<view v-if="item.code == '0001'" @click="handleClickTopimgSearch">
					<topIMgsCCrr ref="topimgSearch" :bgUrl="item.info.imgUrl" @textIndexmethod="getEduInfoCCrr">
						<view :class="['text_content_ccrr', haveTakeNumSta ? 'have_take_num_ccrr' : '']">
							<text v-if="certificaIsPasseSta"
								class="top_tet_ccrr">{{ haveTakeNumSta ? '可用额度' : '预估可领' }}</text>
							<text v-else class="top_tet_ccrr">{{ '预估可领' }}</text>
							<view style="margin-bottom: 0rpx;">
								<text class="edu_tet_ccrr">{{ haveTakeNumSta ? balanceEdu : '50000' }}<text
										style="font-size: 30rpx;margin-left: 4rpx;">元</text></text>
								<view class="buketixian">(不可提现)</view>
							</view>

							<view>
								<view class="lingquedu" v-if="!haveTakeNumSta">领取额度</view>
								<view v-else class="lingqusousuo" @click.stop="toSearchPage">
									<image class="sousuo_img" src="../../static/RICHhome/RICHsearch-2.png"></image>
									<view class="sousuo_wenzi">搜索</view>
								</view>
							</view>
						</view>
					</topIMgsCCrr>
				</view>
				<!-- 十个分类 -->
				<view v-if="item.code == '0002'">
					<tenFenleiCCrr v-if="item.category" :typesList="item.category"></tenFenleiCCrr>
				</view>
				<!-- 轮播图 -->
				<view v-if="item.code == '0009'">
					<lunbotuCCrr v-if="item.images.length != 0" :imagesList="item.images"></lunbotuCCrr>
				</view>
				<!-- 三个小提示 现在换成图片展示-->
				<view v-if="item.code == '0003'">
					<gongGaoCCrr></gongGaoCCrr>
				</view>
				<!-- 三宫格2--横向排列的三张图片 -->
				<view v-if="item.code == '0015'">
					<threeImgsCCrr v-if="item.tap.length != 0" :threeList1="item.tap"></threeImgsCCrr>
				</view>
				<!-- 小轮播 三宫格-->
				<view v-if="item.code == '0010'">
					<sanGongGeCCrr v-if="item.tap.length != 0" :threeList="item.tap"></sanGongGeCCrr>
				</view>
				<!-- 小轮播 四宫格-->
				<view v-if="item.code == '0004'">
					<siGongGeCCrr v-if="item.tap.length != 0" :fourList="item.tap"></siGongGeCCrr>
				</view>
				<!-- 一张图片 -->
				<view v-if="item.code == '0007'">
					<oneImgCCrr :oneList="item"></oneImgCCrr>
				</view>
				<!-- 京东专属卡区 -->
				<view v-if="item.code == '0008'">
					<jingdongCardCCrr></jingdongCardCCrr>
				</view>
				<!-- 热租 不带顶部滚动栏 -->
				<view v-if="item.code == '0005'">
					<rezuRezuCCrr :infoObj="item.info" :productList="item.product"></rezuRezuCCrr>
				</view>
				<!-- 新增的两个组件 -->
				<view v-if="item.code == '0013'">
					<rezuImgCCrr v-if="item.product" :infoObj="item" :productList="item.product"></rezuImgCCrr>
				</view>
				<view v-if="item.code == '0014'">
					<newZhuanquCCrr v-if="item.product" :infoObj="item" :zhuanquList="item.product"></newZhuanquCCrr>
				</view>
				<!-- 最下面的专区分类 带有主副标题 -->
				<view v-if="item.code == '0011'">
					<tabZhuanquCCrr v-if="item.tap.length != 0" :labelGoodslist="item.tap"></tabZhuanquCCrr>
				</view>
				<!-- 最下面的专区分类带图片 -->
				<view v-if="item.code == '0006'">
					<daXiaoTitTypeCCrr v-if="item.product" :zhuanquList="item"></daXiaoTitTypeCCrr>
				</view>
				<!-- 商家入驻 -->
				<view v-if="item.code == '0019'">
					<shangjiaRuzhuCCrr :businessObj="item.info"></shangjiaRuzhuCCrr>
				</view>
				<!-- 新版的热租2——上传的图片是小的而且带有标题字 -->
				<view v-if="item.code == '0020'">
					<rezuImgCCrr1 v-if="item.product" :infoObj="item" :productList="item.product"></rezuImgCCrr1>
				</view>
			</view>
			<view class="homeBotCCrr">
				<text style="text-align: center; font-size: 12px; color: #ccc">我也是有底线的哦~~~</text>
			</view>
		</view>
		<u-no-network></u-no-network>
	</view>
</template>
<script>
	import tabZhuanquCCrr from '../../components/wei-components/index-zhuanqu-rich.vue';
	import oneImgCCrr from '../../components/wei-components/whole-block-rich.vue';
	import lunbotuCCrr from '../../components/wei-components/big-lbt-rich.vue';
	import daXiaoTitTypeCCrr from '../../components/wei-components/bottom-types-rich.vue';
	import rezuRezuCCrr from '../../components/wei-components/index-rezu-rich.vue';
	import rezuImgCCrr1 from '../../components/wei-components/mostnew-rezu-rich.vue';
	import shareFriCCrr from '../../components/wei-components/share-friend-rich.vue';
	import sanGongGeCCrr from '../../components/wei-components/small-lbt-rich.vue';
	import tenFenleiCCrr from '../../components/wei-components/index-type2-rich.vue';
	import topIMgsCCrr from '../../components/wei-components/topimg-search-rich.vue';
	import newZhuanquCCrr from '../../components/wei-components/newnew-zhuanqu-rich.vue';
	import rezuImgCCrr from '../../components/wei-components/newnew-rezu-rich.vue';
	import threeImgsCCrr from '../../components/wei-components/new-threeimg-rich.vue';
	import shangjiaRuzhuCCrr from '../../components/wei-components/business-settle-rich.vue';
	import searchBoxCCrr from '../../components/wei-components/top-search1-rich.vue';
	import jingdongCardCCrr from '../../components/wei-components/new-person-rich.vue';
	import siGongGeCCrr from '../../components/wei-components/small-lbt1-rich.vue';
	import gongGaoCCrr from '../../components/wei-components/three-tips-rich.vue';
	import {
		getUserId,
		checkHasShiMingRenZheng,
		checkHasPhone,
		saveUserReceive,
		saveUserBalance,
		saveUserId,
		saveZWZUserDetail,
		getZWZUserDetail
	} from '@/utils';

	export default {
		data() {
			return {
				haveTakeNumSta: false,
				certificaIsPasseSta: false,
				timerDingshi: null,
				balanceEdu: '',
				searchBgcolor: '#ffffff',
				newZuJianList: [],
				uniPlatform: '',
				stateLanHei: 0,
				userId: '',
				topHeight: 20,




				//下面是没用的垃圾混淆代码
				renzhengTimeSta1111111: true, //初次请求认证时间默认是带有的，
				zhuceTimeSta11111: false, //初次请求注册时间默认是没有的
				renzhengTimeList11111: [],
				zhuceTimeStaList1111: null,
				detailOrderIdStr11111: '',
				threeTabCurrent1111: 0,
				applyGOodsList11111: [], //供货商列表
				allCardEnterSta1111: false, //默认是false，点击批量卡券入库的时候变为true
				codeAddNumsList11111: [],
				numsList11111: [],
				dataSourceBqcp1111: [],
				selectedRowKeys1111: [],
				selectedRowKeysB11111: [],
				rkVisible11111: false,
				rkjlVisible1111: false,
				lhjlVisible1111: false,
				currentStyleData22222: {},
				dataSourceStyle2222: [],
				showStyleData2222: false,
				indexTemplate2222: [],
				SVGCircleElement3ee: '',
				vshoweqwsc1111: false,
				showStyleDataInfo2222: false,
				opeCategoryList2222: [],
				leimuVisible2222: false,
				selectedRowKeys02222: [],
				selectionRows02222: [],
				selectedRowKeys133333: [],
				selectionRows13333: [],
				selectedRowKeys2333: [],
				selectionRows23333: [],
				selectedRowKeys33333: [],
				selectionRows33333: [],
				selectedRowKeys4333: [],
				selectionRows43333: [],
				curwfqwrentStyleDaterwaInfo444: {},
				currwerentStywerleDatweraInfo1444: {},
				currewerntStyleDataInfo24444: {},
				currentweStyleDytuataIwenfo34444: {},
				currenwetStdfgyleDataInfo44444: {},
				checkZfbPhone_h5444: '',
				plNafgdvfdtjyme4444: '', //四大品类的名字
				uniPdfgrtylatform444: '', //运行环境mp-alipay mp-weixin
				refgjtytrsemark555: '', //备注
				timefgjSelStr5555: '', //选择的上门时间（2023-08-31 00:00:00）
				amOdcuiofasrpm5555: '', //选择的上门时间是上午还是下午
				pageShnjlkgohowTime5555: '', //页面上用户看到的显示的时间
				paraghsdfmsw454: {},
				valhgujtueNum56756: 0,
				addrdraess56756: {}, //上门收货地址
				adawerterydressId575: 0,
				sceoyuitne57567: '',
				tntuiopId56757: '',
				weictyuratCustomer5756: '',
				yuidurtyuoy567567: false,
			};
		},
		components: {
			gongGaoCCrr,
			topIMgsCCrr,
			lunbotuCCrr,
			sanGongGeCCrr,
			siGongGeCCrr,
			daXiaoTitTypeCCrr,
			rezuRezuCCrr,
			tenFenleiCCrr,
			searchBoxCCrr,
			jingdongCardCCrr,
			tabZhuanquCCrr,
			oneImgCCrr,
			newZhuanquCCrr,
			rezuImgCCrr,
			threeImgsCCrr,
			shangjiaRuzhuCCrr,
			rezuImgCCrr1,
			shareFriCCrr
		},
		onLoad() {
			if (uni.getSystemInfoSync().statusBarHeight != 0) {
				this.topHeight = uni.getSystemInfoSync().statusBarHeight
			}
			this.uniPlatform = getApp().globalData.uniPlatform;
			this.stateLanHei = getApp().globalData.statusBarHeight;
			this.userId = getUserId()
		},
		onPullDownRefresh() {
			this.getZujianList(0, 3);
		},
		onReachBottom() {},
		//触底刷新接口
		onReachBottom() {
			this.onScrollToLower();
		},
		mounted() {
			uni.getSystemInfo({
				success: function(res) {
					console.log('获取手机硬件信息', res)
				}
			});
		},
		watch: {
			data(newValue, oldValue) {}
		},
		onShow() {
			if (uni.getSystemInfoSync().statusBarHeight != 0) {
				this.topHeight = uni.getSystemInfoSync().statusBarHeight
			}
			if (this.newZuJianList.length == 0) {
				this.getZujianList(0, 3);
			}
			// #ifdef H5
			this.getUrlCode()
			// #endif
		},
		onHide() {
			clearInterval(this.timerDingshi);
			this.timerDingshi = null;
		},
		methods: {
			getUrlCode() {
				let str = window.location.href;
				// let str =
				// 'https://h5.rich.nbzqs.com/?auth_code=e8149cb82a334f7794ffa4942b08KD92&app_id=2021003165647099&source=alipay_wallet&scope=auth_user&state=init#/';
				if (str.indexOf("auth_code") != -1) {
					let obj = {};
					let arr1 = str.split("?");
					let arr2 = arr1[1].split("&");
					for (let i = 0; i < arr2.length; i++) {
						let res = arr2[i].split("=");
						obj[res[0]] = res[1];
					}
					// console.log('支付宝返回的obj.auth_code', obj.auth_code);
					// console.log('解析当前页面url参数', obj);;
					//把支付宝给的auth_code走接口，拿到uid和手机号（有手机号直接提示，没有手机号直接跳转新页面）
					this.alipayLoginH5(obj.auth_code)
				}
			},
			alipayLoginH5(authCode) {
				this.$request('member/mall/aliPay/user/alipayLogin', {
						authCode: authCode,
						source: '1',
					}, 'post', false, true).then((
						res) => {
						if (res.businessSuccess || res.success) {
							if (res.data && res.data.uid) {
								saveUserId(res.data.uid);
								saveZWZUserDetail(res.data);
							}
							if (res.data.telephone) {
								let timer1 = null
								timer1 = setTimeout(() => {
									if (getUserId() && getZWZUserDetail().token) {
										this.getCertificaCCrr();
										this.getEduInfoCCrr();
									}
									timer1 = null
									clearTimeout(timer1);
								}, 500); // 延迟0.5秒
							} else {
								this.$onTo(`/pagesOther/appLoginphone/appLoginphone?uid=res.data.uid`)
								// this.$onTo(`/pagesOther/loginphoneH5/loginphoneH5?uid=123456`)
							}
						}
					})
					.catch(res => {
						uni.showToast({
							title: '授权登录失败，请返回重试',
							icon: 'none',
							duration: 2000,
						});
					})
			},





			toZfb() {
				uni.getSystemInfo({
					success: function(res) {
						console.log('获取手机硬件信息', res)
						uni.showToast({
							icon: 'none',
							title: res.deviceId
						});
					}
				});
			},
			//跳转搜索页
			toSearchPage() {
				this.$onTo(`/pagesClass-rich/search-rich/search-rich`)
			},
			getCertificaCCrr() {
				if (this.$getUid()) {
					checkHasShiMingRenZheng()
						.then((obj) => {
							this.certificaIsPasseSta = obj.checkResult;
							this.haveTakeNumSta = obj.isReceive;
							saveUserReceive(obj.isReceive)
						})
						.catch(() => {

							this.certificaIsPasseSta = false;
							this.haveTakeNumSta = false;
						});
				}
			},
			//获取额度信息
			async getEduInfoCCrr() {
				if (!this.$getUid()) {
					clearInterval(this.timerDingshi);
					return;
				}
				await this.getCertificaCCrr();
				this.$request('member/mall/aliPay/balanceTradeRecord/getBalanceInfo', {
						userId: getUserId()
					}, 'POST')
					.then((res) => {
						if (res.businessSuccess) {
							if (res.data === undefined || res.data === null) {
								this.balanceEdu = '';
							} else {
								this.balanceEdu = res.data;
								saveUserBalance(res.data)
							}
							setTimeout(() => {
								getApp().globalData.balanceEdu = this.balanceEdu;
							}, 0);
							// if (!this.timerDingshi) {
							// 	let intervalTime = process.env.NODE_ENV === 'development' ? 1000 * 60 * 5 : 5000;
							// 	this.timerDingshi = setInterval(() => {
							// 		this.getEduInfoCCrr();
							// 	}, intervalTime);
							// }
						} else {
							clearInterval(this.timerDingshi);
						}
					})
					.catch(() => clearInterval(this.timerDingshi));
			},
			//获取首页组件数据
			getZujianList(sNum, eNum) {
				// mall-applets/mall-api/product/mall/style/home?start=0&end=3
				this.$request(`product/mall/style/home?start=${sNum}&end=${eNum}`, {}, 'GET', false)
					.then((res = {}) => {
						if (res.list && res.list.length > 0) {
							this.newZuJianList = res.list;
							res.list.some((item) => {
								if (item.info && item.info.backColors) {
									this.searchBgcolor = item.info.backColors.slice(0, 7);
									return true;
								}
							});
							const topSearchItem = res.list.find((item) => item.code == '0001');
							if (topSearchItem) {
								uni.setStorage({
									key: 'themeColor',
									data: topSearchItem.info.backColors,
									success() {
										console.log('设置主题色');
									}
								});
							}
							const hotAreaItem = res.list.find((item) => item.code == '0020');
							if (hotAreaItem) {
								uni.setStorage({
									key: 'rezuListState',
									data: JSON.stringify(hotAreaItem.product),
									success() {}
								});
								uni.setStorage({
									key: 'rezuCode',
									data: 'yes',
									success() {}
								});
							} else {
								uni.setStorage({
									key: 'rezuListState',
									data: null,
									success() {}
								});
								uni.setStorage({
									key: 'rezuCode',
									data: 'no',
									success() {}
								});
							}

							uni.stopPullDownRefresh();
						} else {
							uni.setStorage({
								key: 'rezuListState',
								data: null,
								success() {
									console.log('热租数据null存储成功！');
								}
							});
							uni.setStorage({
								key: 'rezuCode',
								data: 'no',
								success() {
									console.log('热租code---no存储成功！');
								}
							});
						}
					})
					.then(() => this.getProductList());
			},
			getProductList() {
				this.$request(`product/mall/style/home?start=3&end=0`, {}, 'GET', false).then((res) => {
					if (res.list && res.list.length > 0) {
						this.newZuJianList = this.newZuJianList.concat(res.list);
					}
				});
			},
			//新的接口获取热销产品---触底刷新接口
			onScrollToLower() {
				uni.showToast({
					icon: 'none',
					title: '小主，没有更多啦～'
				});
			},
			handleClickTopimgSearch() {
				this.$refs.topimgSearch[0].getBalance();
			}
		}
	};
</script>

<style lang="scss" scoped>
	@font-face {
		font-family: 'Number';
		font-style: normal;
		font-weight: 400;
		src: url(../../static/font/number.woff) format('woff');
	}

	/* 新版首页的css */
	.homeBoxChaoren {
		background: #f5f5f5;
		position: relative;

		.bjBoxCCrr {
			overflow-x: hidden;
			position: relative;
			width: 100%;

			.text_content_ccrr {
				height: 100%;
				display: flex;
				flex-direction: column;
				justify-content: space-evenly;
				color: #fff;
				position: absolute;
				width: 100%;
				left: 0rpx;
				top: 0rpx;
				margin-left: 60rpx;


				.top_tet_ccrr {
					font-size: 48rpx;
					// margin-bottom: 20rpx;
					letter-spacing: 0.1em;
					margin-top: 20rpx;

					.small_wenzi {
						font-size: 24rpx;
						margin-left: 8rpx;
					}
				}

				.bot_tet_ccrr {
					border-radius: 100px;
					font-family: PingFangSC-Medium, PingFang SC;
					background: linear-gradient(135deg, #c850c0, #4158d0);
					padding: 5rpx 0;
					font-size: 26rpx;
					// margin-top: 20rpx;
					text-align: center;
					min-width: 150rpx;
					width: 180rpx;
				}

				.edu_tet_ccrr {
					line-height: 1;
					font-family: 'Number';
					font-size: 65rpx;
					letter-spacing: 0.03em;
				}

				.buketixian {
					font-size: 24rpx;
					letter-spacing: 0.2em;
				}

				.lingquedu {
					width: 29%;
					text-align: center;
					padding: 8rpx;
					margin-top: 50rpx;
					margin-bottom: 30rpx;
					border-radius: 50rpx;
					background-color: #fff5eb;
					color: #be9264;
					letter-spacing: 0.03em;
					font-size: 25rpx;
					font-weight: 600;
				}

				.lingqusousuo {
					display: flex;
					align-items: center;
					justify-content: space-between;
					width: 29%;
					text-align: center;
					padding: 8rpx;
					// margin-top: 20rpx;
					border-radius: 50rpx;
					background-color: #fff5eb;
					color: #be9264;
					letter-spacing: 0.03em;
					font-size: 25rpx;
					font-weight: 600;

					.sousuo_img {
						width: 35rpx;
						height: 35rpx;
						margin-left: 20rpx;
						margin-right: 20rpx;
					}

					.sousuo_wenzi {
						margin-right: 20rpx;
					}
				}


				.top_btn_box {
					display: flex;
					align-items: center;
					// position: absolute;
					width: 100%;
					// left: 80rpx;
					// bottom: 50rpx;
					// margin-left: 50rpx;

					&_lingqu {
						width: 35%;
						padding: 13rpx;
						text-align: center;
						// margin: 0 auto;
						border-radius: 50rpx;
						// margin-left: 50rpx;
						// margin-right: 50rpx;
						background-color: #ffffff;
						color: #be9264;
						letter-spacing: 0.03em;
						font-size: 28rpx;
						font-weight: 600;
						// box-shadow: -1rpx 4rpx 5rpx 3rpx #fd7115;

					}

					&_sousuo {
						display: flex;
						align-items: center;
						// justify-content: flex-start;
						width: 35%;
						padding: 13rpx;
						// margin: 0 auto;
						border-radius: 50rpx;
						background-color: #fff5eb;
						color: #be9264;
						letter-spacing: 0.03em;
						font-size: 28rpx;
						font-weight: 600;

						.sousuo_img {
							width: 35rpx;
							height: 35rpx;
							margin-left: 20rpx;
							margin-right: 20rpx;
						}

						.sousuo_wenzi {
							font-size: 24rpx;
							color: #a5a5a5;
						}

						.sousuo_tit {
							margin-left: auto;
							font-size: 24rpx;
							font-weight: lighter;
							color: #ffffff;
							padding: 6rpx 15rpx;
							border-radius: 30rpx;
							background-color: #ff9b30;
						}

					}
				}

				&.have_take_num_ccrr {
					bottom: 64rpx;
				}
			}

			.top_btn_box {
				display: flex;
				align-items: center;
				position: absolute;
				width: 100%;
				left: 80rpx;
				bottom: 50rpx;

				// margin-left: 50rpx;

				&_lingqu {
					width: 35%;
					padding: 13rpx;
					text-align: center;
					// margin: 0 auto;
					border-radius: 50rpx;
					// margin-left: 50rpx;
					// margin-right: 50rpx;
					background-color: #ffffff;
					color: #be9264;
					letter-spacing: 0.03em;
					font-size: 28rpx;
					font-weight: 600;
					// box-shadow: -1rpx 4rpx 5rpx 3rpx #fd7115;

				}

				&_sousuo {
					display: flex;
					align-items: center;
					// justify-content: flex-start;
					width: 35%;
					padding: 13rpx;
					// margin: 0 auto;
					border-radius: 50rpx;
					background-color: #fff5eb;
					color: #be9264;
					letter-spacing: 0.03em;
					font-size: 28rpx;
					font-weight: 600;

					.sousuo_img {
						width: 35rpx;
						height: 35rpx;
						margin-left: 20rpx;
						margin-right: 20rpx;
					}

					.sousuo_wenzi {
						font-size: 24rpx;
						color: #a5a5a5;
					}

					.sousuo_tit {
						margin-left: auto;
						font-size: 24rpx;
						font-weight: lighter;
						color: #ffffff;
						padding: 6rpx 15rpx;
						border-radius: 30rpx;
						background-color: #ff9b30;
					}

				}
			}
		}

		.homeBotCCrr {
			text-align: center;
		}

	}
</style>